package com.example.administrator.hqq.adapter.module;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.example.administrator.hqq.R;
import com.example.administrator.hqq.bean.group.GetGroupSettingsBean;
import com.example.administrator.hqq.utils.transform.GlideCircleTransform;
import com.example.administrator.hqq.utils.transform.GlideRoundTransform;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @name: HQQ
 * @describe:
 * @author: 康海涛 QQ2541849981
 * @time: 2018/11/16 10:20
 * @remark:
 */
public class GroupSettingGridAdater extends BaseAdapter {
    private List<GetGroupSettingsBean.DataBean.MemberBean> list;
    private Context context;
    private boolean isShowDeleteButton=false;

    public void setShowDeleteButton(boolean showDeleteButton) {
        isShowDeleteButton = showDeleteButton;
    }

    public boolean isShowDeleteButton() {
        return isShowDeleteButton;
    }

    public GroupSettingGridAdater(List<GetGroupSettingsBean.DataBean.MemberBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        if (isShowDeleteButton)
        {
            return list.size()+1;
        }
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.group_chat_setting_item, viewGroup, false);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        if (isShowDeleteButton&&list.size()==i)
        {
            viewHolder.groupChatMember.setVisibility(View.GONE);
            viewHolder.kickMember.setVisibility(View.VISIBLE);
            viewHolder.kickMember.setImageResource(R.drawable.delete);
            viewHolder.title.setText("");
        }
        else{
            viewHolder.groupChatMember.setVisibility(View.VISIBLE);
            viewHolder.kickMember.setVisibility(View.GONE);
            viewHolder.title.setVisibility(View.VISIBLE);
            Glide.with(context).load(list.get(i).getUrl())
                    .transform(new CenterCrop(context),new GlideCircleTransform(context))
                    .into(viewHolder.groupChatMember);
            viewHolder.title.setText(list.get(i).getName());
        }
        return view;
    }

    static class ViewHolder {
        @BindView(R.id.group_chat_member)
        ImageView groupChatMember;
        @BindView(R.id.title)
        TextView title;
        @BindView(R.id.kick_member)
        ImageView kickMember;
        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
